package org.example.completed.controller;


import org.example.completed.domain.AdoptionCloudSituationDO;
import org.example.completed.model.vo.ResultVO;
import org.example.completed.service.AdoptionCloudSituationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 云领养宠物近况表
 *
 * @since 2025-04-15
 */
@RestController
@RequestMapping("/adoptionCloudSituationDO")
public class AdoptionCloudSituationController {
    @Autowired
    private AdoptionCloudSituationService adoptionCloudSituationService;

    /**
     * 根据云领养成功记录表id查询云领养宠物近况记录
     * @param cloudRecordId 云领养成功记录表id
     * @return 云领养宠物近况实体
     */
    @GetMapping("/getByCloudRecordId/{cloudRecordId}")
    public ResultVO<List<AdoptionCloudSituationDO>> getByCloudRecordId(@PathVariable String cloudRecordId) {
        List<AdoptionCloudSituationDO> adoptionCloudSituationDOs = adoptionCloudSituationService.getByCloudRecordId(cloudRecordId);
        return adoptionCloudSituationDOs != null ? ResultVO.ok(adoptionCloudSituationDOs) : ResultVO.fail(404, "未找到记录");
    }

    /**
     * 新增云领养宠物近况记录
     * @param adoptionCloudSituationDO 云领养宠物近况实体
     * @return 操作结果
     */
    @PostMapping("/add")
    public ResultVO<Boolean> add(@RequestBody AdoptionCloudSituationDO adoptionCloudSituationDO) {
        boolean saveResult = adoptionCloudSituationService.save(adoptionCloudSituationDO);
        return saveResult ? ResultVO.ok() : ResultVO.fail(500, "新增失败");
    }

    /**
     * 删除云领养宠物近况记录
     * @param id 记录ID
     * @return 操作结果
     */
    @PostMapping("/delete/{id}")
    public ResultVO<Boolean> delete(@PathVariable String id) {
        boolean removeResult = adoptionCloudSituationService.removeById(id);
        return removeResult ? ResultVO.ok() : ResultVO.fail(500, "删除失败");
    }

    /**
     * 修改云领养宠物近况记录
     * @param adoptionCloudSituationDO 云领养宠物近况实体
     * @return 操作结果
     */
    @PostMapping
    public ResultVO<Boolean> update(@RequestBody AdoptionCloudSituationDO adoptionCloudSituationDO) {
        boolean updateResult = adoptionCloudSituationService.updateById(adoptionCloudSituationDO);
        return updateResult ? ResultVO.ok() : ResultVO.fail(500, "修改失败");
    }

    /**
     * 查询单个云领养宠物近况记录
     * @param id 记录ID
     * @return 云领养宠物近况实体
     */
    @GetMapping("/{id}")
    public ResultVO<AdoptionCloudSituationDO> getById(@PathVariable String id) {
        AdoptionCloudSituationDO adoptionCloudSituationDO = adoptionCloudSituationService.getById(id);
        return adoptionCloudSituationDO != null ? ResultVO.ok(adoptionCloudSituationDO) : ResultVO.fail(404, "未找到记录");
    }

    /**
     * 查询所有云领养宠物近况记录
     * @return 云领养宠物近况记录列表
     */
    @GetMapping
    public ResultVO<List<AdoptionCloudSituationDO>> getAll() {
        List<AdoptionCloudSituationDO> list = adoptionCloudSituationService.list();
        return ResultVO.ok(list);
    }



}

